<%@ page language="java" contentType="text/html; charset=UTF-8"  isELIgnored="false"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="../../css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="../../js/jquery-2.1.4.js"></script>
<script src="../../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/path.js"></script>
<style>
	td {
		text-align: center;
		width:50%;
	}
	
	#container {
		width: 70%;
		margin-left: 200px;
	}
	
	#jieguo1,#jieguo2 {
		color: red;
	}
	
	.close{
		float: right;
	}
	
	#updatePage {
		width: 50%;
	}
	button{
		background-color: greenyellow;
	}
</style>
</head>

<body>
	<table border="1 " cellspacing="0 " align="center" class='updateTable'>
					
		<tr>
			<td colspan="2" align="center">
				公司信息修改
				<input type="button" value="点此关闭" style="font-family: '微软雅黑';font-size: 5px; background-color: red;" onclick='closeUpPage();' class='close'/>
			</td>
			
		</tr>
		
		<tr>
			<td>公司名称</td>
			<td>
				<input type="text"  name="updateName"  onblur="yzName();"/>
				<div id="jieguo1"></div>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<input type="button" id="but1" value="修改 " style="background-color: gold"/>
				
			</td>
		</tr>
	</table>
	<div id='jieguo'></div>
	<script type="text/javascript">
		//得到银行卡的ID
		var id = ${param.id};
		function yzName(){
			var cardNo = $('input[name="updateName"]').val();
			if(""==cardNo ||  null == cardNo){
				$('#jieguo1').text("请重新输入...");
				return false;
			}else{
				$('#jieguo1').empty();
				return true;
			}
		}
		
		//修改方法开始
		$('#but1').click(function(){
			//先验证数据的正确性
			//验证输入的卡号和余额
			if(yzName()){
				//正确时在进行修改
				
				var name=$('input[name=updateName]').val();
				$.ajax({
					data:{
				
					'id':id,
					'name':name
					},
					url:getPath()+"/company/updateById",
					type:'post',
					dataType:'json',
					success:function(jsonData){
						if(jsonData.result=='success'){
							window.location.href="company-list.html";
						}else{
							$('#jieguo').text(jsonData.jieguo);
						}
					}
					
				})
			}
		});
		
		$(function(){
			//alert(id);
			//2拿到对应的所有信息开始
			$.ajax({
				data:{
				
					'id':id,
				},
				url:getPath()+"/company/findCompanyById",
				type:'post',
				dataType:'json',
				success:function(jsonData){
					
					console.log(jsonData);
					
					$('input[name="updateName"]').val(jsonData.data.name);
				}
			})
			
		});
	</script>
</body>
</html>